package com.wao.product.service.mapper;

import com.wao.product.domain.Product;
import com.wao.product.service.dto.ProductAttributeDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

/**
 * Mapper for the entity Product and its DTO ProductDTO.
 */
@Mapper(componentModel = "spring", uses = {BrandMapper.class, PictureMapper.class, AttributeMapper.class})
public interface ProductAttributeMapper extends EntityMapper<ProductAttributeDTO, Product> {

    @Mapping(source = "brand.id", target = "brandId")
    @Mapping(source = "brand.name", target = "brandName")
    ProductAttributeDTO toDto(Product product);

    @Mapping(source = "brandId", target = "brand")
    Product toEntity(ProductAttributeDTO productAttributeDTO);

    default Product fromId(Long id) {
        if (id == null) {
            return null;
        }
        Product product = new Product();
        product.setId(id);
        return product;
    }
}
